//
//  CorgiStatusBottomView.swift
//  weibo
//
//  Created by Corgi on 17/3/24.
//  Copyright © 2017年 cocoaHangTou. All rights reserved.
//

import UIKit

class CorgiStatusBottomView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
         setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func setupUI() {
        
        //backgroundColor = randomColor()
        backgroundColor = UIColor.white
        
        let retweetButton = addchildBtns(imageName: "timeline_icon_retweet", title: "转发")
        let commentButton = addchildBtns(imageName: "timeline_icon_comment", title: "评论")
        let unlikeButton = addchildBtns(imageName: "timeline_icon_unlike", title: "赞")
        
        let line1 = addChildLines()
        let line2 = addChildLines()
        
        retweetButton.snp.makeConstraints { (make) in
            make.left.top.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        
        commentButton.snp.makeConstraints { (make) in
            make.top.bottom.equalTo(self)
            make.left.equalTo(retweetButton.snp.right)
            make.width.equalTo(unlikeButton)
        }
        
        unlikeButton.snp.makeConstraints { (make) in
            make.top.right.bottom.equalTo(self)
            make.left.equalTo(commentButton.snp.right)
        }
        
        line1.snp.makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.centerX.equalTo(retweetButton.snp.right)
            make.height.equalTo(20)
        }
        
        line2.snp.makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.centerX.equalTo(unlikeButton.snp.left)
            make.height.equalTo(20)
        }
        
        
        
    }
    
}

extension CorgiStatusBottomView {

    fileprivate func addchildBtns(imageName: String, title: String) -> UIButton{
        
        let btn = UIButton()
        
        btn.setTitle(title, for: .normal)
        
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        
        btn.titleLabel?.font = UIFont.systemFont(ofSize: FONTSIZEOFNORMAL)
        
        btn.setImage(UIImage(named:imageName), for: .normal)
        
        btn.setBackgroundImage(UIImage(named:"timeline_card_bottom_background"), for: .normal)
        
        btn.setBackgroundImage(UIImage(named:"timeline_card_bottom_background_highlighted"), for: .highlighted)
        
        addSubview(btn)
        
        return btn
    }

    fileprivate func addChildLines() -> UIImageView {
        
        let img = UIImageView(imageName: "timeline_card_bottom_line")
     
        addSubview(img)
        
        return img
    }
    
}

